<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="/res/css/amazeui.min.css" />
		<link rel="stylesheet" href="/res/css/admin.css" />
	</head>

	<body>
		<div class="admin-content-body">
			<div class="am-cf am-padding am-padding-bottom-0">
				<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">添加学生信息</strong><small></small></div>
			</div>
			<hr>
			<div class="am-g">
				<div class="am-u-sm-12">
					<form class="am-form" action="/students/pc/add" onsubmit="return checkData()" method="post">
						<table class="am-table am-table-striped am-table-hover table-main">
							<tbody>
								<tr>
									<td>姓名</td>
									<td><input type="text" name="name" id="name" placeholder="请输入姓名" /></td>
								</tr>
								<tr>
									<td>性别</td>
									<td><input type="radio" name="sex" value="男" checked="checked"/>&nbsp;男&nbsp;&nbsp;&nbsp;<input type="radio" name="sex" value="女"/>&nbsp;女</td>
								</tr>
								<tr>
									<td>年级</td>
									<td><input type="text" name="grade" id="grade" placeholder="请输入年级" /></td>
								</tr>
								<tr>
									<td>专业</td>
									<td><input type="text" name="major" id="major" placeholder="请输入专业" /></td>
								</tr>
                                <tr>
                                    <td>在校表现</td>
                                    <td>
                                        <select name="conduct">
                                            <option value="优秀">优秀</option>
                                            <option value="良好">良好</option>
                                            <option value="一般">一般</option>
                                            <option value="较差">较差</option>
                                        </select>
                                    </td>
                                </tr>
								<tr>
									<td>是否就业</td>
									<td><input type="radio" name="employment" value="1" checked="checked"/>&nbsp;已就业&nbsp;&nbsp;&nbsp;<input type="radio" name="employment" value="0"/>&nbsp;未就业</td>
								</tr>
								<tr>
									<td>公司</td>
									<td><input type="text" name="employmentCompany" id="employmentCompany" placeholder="请输入就业公司名称，未就业填无" /></td>
								</tr>
								<tr>
									<td>所在城市</td>
									<td><input type="text" name="employmentCity" id="employmentCity" placeholder="请输入公司所在城市，未就业填无" /></td>
								</tr>
								<tr>
									<td>电话</td>
									<td><input type="text" name="phone" id="phone" placeholder="请输入联系电话" /></td>
								</tr>
								<tr>
									<td>微信</td>
									<td><input type="text" name="wechat" id="wechat" placeholder="请输入微信号" /></td>
								</tr>
								<tr>
									<td>QQ</td>
									<td><input type="text" name="qq" id="qq" placeholder="请输入QQ账号" /></td>
								</tr>
								<tr>
									<td>邮箱</td>
									<td><input type="email" name="email" id="email" placeholder="请输入邮箱地址" onblur="checkMail()" onfocus="clean()" /><span id="warning" style="color: red"></span></td>
								</tr>
								<tr>
									<td>密码</td>
									<td><input type="password" name="password" id="password" placeholder="请输入登录密码" /></td>
								</tr>
							</tbody>
						</table>
						<button type="submit" class="am-btn am-btn-success" >提交</button>
					</form>
				</div>
			</div>
		</div>
	</body>
    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
	<script>

        function isEmail(mail) {
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (filter.test(mail)) {
                return true;
            } else {
                return false;
            }
        }

        function clean() {
            $('#warning').html('');
        }

        function checkMail(){
            var email = document.getElementById("email").value;

            if(email==null||email==''||email.trim().length==0){
                return;
            }
            if(!isEmail(email)){
                $('#warning').html('邮箱格式有误，请重新输入');
                return;
            }

            $.ajax({
                type: "get",
                url: "/students/pc/add/check",
                data: "email=" + email,
                dataType: 'html',
                contentType: "application/x-www-form-urlencoded; charset=utf-8",
                success: function(result) {
                    result = JSON.parse(result);

                    if(result["head"]["code"]!=0){
                        //alert(result['head']['msg']);
                        $('#warning').html(result['head']['msg']);
                        return false;
                    }
                    //location.reload();
                }
            });

        }

		function checkData() {
            var name = document.getElementById("name").value;
            var grade = document.getElementById("grade").value;

            var major = document.getElementById("major").value;
            var employmentCompany = document.getElementById("employmentCompany").value;
            var employmentCity = document.getElementById("employmentCity").value;

            var phone = document.getElementById("phone").value;
            var wechat = document.getElementById("wechat").value;
            var qq = document.getElementById("qq").value;
            var email = document.getElementById("email").value;
            var password = document.getElementById("password").value;

            if(name==null||name==''||name.trim().length==0){
                alert("姓名不能为空");
                return false;
            }
            if(grade==null||grade==''||grade.trim().length==0){
                alert("年级不能为空");
                return false;
            }
            if(major==null||major==''||major.trim().length==0){
                alert("专业不能为空");
                return false;
            }
            if(employmentCompany==null||employmentCompany==''||employmentCompany.trim().length==0){
                alert("就业公司不能为空");
                return false;
            }
            if(employmentCity==null||employmentCity==''||employmentCity.trim().length==0){
                alert("就业城市不能为空");
                return false;
            }
            if(phone==null||phone==''||phone.trim().length==0||phone.trim().length<11){
                alert("联系电话格式有误，请重新输入！");
                return false;
            }
            if(wechat==null||wechat==''||wechat.trim().length==0){
                alert("微信号不能为空");
                return false;
            }
            if(qq==null||qq==''||qq.trim().length==0){
                alert("QQ号码不能为空");
                return false;
            }
            if(email==null||email==''||email.trim().length==0){
                alert("邮箱地址不能为空");
                return false;
            }
            if(password==null||password==''||password.trim().length==0){
                alert("密码不能为空");
                return false;
            }
            if(password.length<6){
                alert("密码长度不能小于6位！");
                return false;
            }

            return true;
        }
	</script>
</html>